package com.fanbai.score.user.activity;

import android.widget.TextView;

import com.fanbai.score.R;
import com.fanbai.score.common.Manager.ActivityManager;
import com.fanbai.score.common.Utils.ToastUtils;
import com.fanbai.score.common.base.BaseActivity;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.user.bean.OrderInfo_Bean;
import com.fanbai.score.user.http.UserOrder_RequestNet_Utils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by acer on 2017/5/13.
 * 购物详情
 */

public class ShoppingDetails_Activity extends BaseActivity{

    @BindView(R.id.userActivityPayInfo_jifen)
    TextView jifenText;
    @BindView(R.id.userActivityPayInfo_zongjia)
    TextView zongjiaText;
    @BindView(R.id.userActivityPayInfo_dec)
    TextView decText;

    @OnClick(R.id.userActivityPayInfo_orderOkBut)
    public void onClick(){
        setuseridfororder(oid);
    }
    @Override
    protected int getLayoutID() {
        return R.layout.user_activity_shoppingdetails;
    }

    @Override
    public String getTitleName() {
        return "购物详情";
    }

    @Override
    protected void initView() {

    }

    String oid = "";
    @Override
    protected void initData() {
        oid = getIntent().getExtras().getString("oid");
        getorderinfobyoid(oid);
    }

    private void setViewData(OrderInfo_Bean bean){
        jifenText.setText("积分："+bean.getOscore());
        zongjiaText.setText("总价："+bean.getOtotalprice());
        decText.setText("商品描述\n  "+bean.getOproductdesc());
    }

    @Override
    protected void initListener() {

    }
    @Override
    public int getTitleLeftName() {
        return R.mipmap.back_click;
    }

    @Override
    public void onClickTitleLeft() {
        ActivityManager.getInstance().finishActivity();
    }

    private void getorderinfobyoid(String oid){
        showDialog();
        UserOrder_RequestNet_Utils.getorderinfobyoid(ctx, oid, new CallBack<OrderInfo_Bean>() {
            @Override
            public void onSuccess(String code, String msg, OrderInfo_Bean s) {
                hideDialog();
                setViewData(s);
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }
        });
    }

    private void setuseridfororder(String oid ){
        showDialog();
        UserOrder_RequestNet_Utils.setuseridfororder(ctx, oid, new CallBack<String>() {
            @Override
            public void onSuccess(String code, String msg, String s) {
                hideDialog();
                ToastUtils.RightImageToast(ctx, msg);
                ActivityManager.getInstance().finishActivity();
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }
        });
    }
}
